package com.example.child_protection.controller;

import com.example.child_protection.dto.base.BaseResponseDTO;
import com.example.child_protection.dto.request.SimpleIdRequestDTO;
import com.example.child_protection.dto.request.add.SystemRoleInsertRequestDTO;
import com.example.child_protection.dto.request.find.SystemRoleRequestDTO;
import com.example.child_protection.dto.request.update.SystemRoleUpdateRequestDTO;
import com.example.child_protection.dto.response.SystemRoleListResponseDTO;
import com.example.child_protection.dto.response.SystemRoleResponseDTO;
import com.example.child_protection.service.SystemRoleManageService;
import com.example.child_protection.service.SystemRoleQueryService;
import com.example.child_protection.util.ContentType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 角色信息管理控制层
 * @date 2018-11-2
 * @author Biz
 */
@RestController
@RequestMapping("systemRole")
@Api(value = "/api-systemRole", description = "角色信息管理")
public class SystemRoleController extends BaseController {

    @Autowired
    public SystemRoleManageService systemRoleManageService;

    @Autowired
    public SystemRoleQueryService systemRoleQueryService;

    @ApiOperation(value ="查询角色信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findId", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public SystemRoleResponseDTO findId(SimpleIdRequestDTO requestDTO,HttpServletRequest request)throws Exception{
        logger.info("用户ID{},sessionId{}",request.getSession().getAttribute("user"),request.getSession().getId());
        SystemRoleResponseDTO responseDTO = systemRoleQueryService.findId(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="查询角色列表信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findList", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public SystemRoleListResponseDTO findList(SystemRoleRequestDTO requestDTO, HttpServletRequest request)throws Exception{
        SystemRoleListResponseDTO responseDTO = systemRoleQueryService.findList(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="添加角色信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/insert", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO insert(SystemRoleInsertRequestDTO requestDTO)throws Exception{
        requestDTO.setCreatePersonId(this.getLoginUserId());
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = systemRoleManageService.insert(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="修改角色信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO update(SystemRoleUpdateRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = systemRoleManageService.update(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="删除角色信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO delete(SimpleIdRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = systemRoleManageService.delete(requestDTO);
        return responseDTO;
    }

}
